package io.openmessaging.storage.dledger.protocol;

import static io.openmessaging.storage.dledger.protocol.VoteResponse.RESULT.UNKNOWN;

public class VoteResponse extends RequestOrResponse {

    //
    public RESULT voteResult = UNKNOWN;

    public VoteResponse() {

    }

    public VoteResponse(VoteRequest request) {
        copyBaseInfo(request);
    }

    public RESULT getVoteResult() {
        return voteResult;
    }

    public void setVoteResult(RESULT voteResult) {
        this.voteResult = voteResult;
    }

    public VoteResponse voteResult(RESULT voteResult) {
        this.voteResult = voteResult;
        return this;
    }

    public VoteResponse term(long term) {
        this.term = term;
        return this;
    }

    public enum RESULT {
        UNKNOWN,
        ACCEPT,
        REJECT_UNKNOWN_LEADER,
        REJECT_UNEXPECTED_LEADER,
        REJECT_EXPIRED_VOTE_TERM,
        REJECT_ALREADY_VOTED,
        REJECT_ALREADY_HAS_LEADER,
        REJECT_TERM_NOT_READY,
        REJECT_TERM_SMALL_THAN_LEDGER,
        REJECT_EXPIRED_LEDGER_TERM,//拒绝票，原因是自己维护的 ledgerTerm 小于对端维护的 ledgerTerm
        REJECT_SMALL_LEDGER_END_INDEX,//拒绝票，原因是对端的 ledgerTeam与自己维护的ledgerTeam相等，轮次相等 ,
        // 但自己维护的 LedgerEndIndex 小于对端维护的值， 日志序列小了
        REJECT_TAKING_LEADERSHIP;
    }

    public enum ParseResult {
        //等待去投票
        WAIT_TO_REVOTE,
        //立马投票
        REVOTE_IMMEDIATELY,
        //通过
        PASSED,
        //等待下一轮 投票  当前轮投票没有结果
        WAIT_TO_VOTE_NEXT;
    }
}
